import Vue from 'vue'
import Router from 'vue-router'
import auth from '@/utils/auth'
import home from './routes/home'
import login from './routes/login'
import my from './routes/my'
import putforward from './routes/putforward'
import putrelease from './routes/putrelease'


Vue.use(Router)

const router = new Router({
  // mode: 'history',
  base: process.env.BASE_URL,

  routes: [
    login,
    home
  ]
})



router.beforeEach((to, from, next) => {
  if (to.meta.title) { //判断是否有标题
    document.title = to.meta.title
  }
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!auth.loggedIn()) {
      window.location.href = '/auth/login/logout'
      next()
    } else {
      next()
    }
  } else {
    next()
  }
})

router.afterEach((to, from, next) => {})

export default router